﻿using Microsoft.AspNetCore.Mvc;
using ZhCun.DBModel;
using ZhCun.RightsManage.AL;
using ZhCun.Utils;
using ZhCun.WebUtils.VModel;

namespace ZhCun.WebUtils.ApiControllers.RightsManage
{
    [ApiExplorerSettings(GroupName = "RightsManage")]
    public class ApiRoleController : BaseApiCrudController<RoleBLL, ArgGetList, Sys_Role>
    {
        /// <summary>
        /// 得到所有属性菜单数据结果（layui tree 格式）
        /// </summary>
        [HttpPost]
        public ApiResultList<LayuiTreeModel> GetMenuTree(ArgId arg)  //string roleId)
        {
            return BLLObj.GetLayuiMenuTree(arg.Id);
        }
        /// <summary>
        /// 获取角色的菜单列表，用于配置
        /// </summary>
        [HttpPost]
        public ApiResultList<VSys_RoleMenu> GetRoleMenus(ArgId arg)
        {
            return BLLObj.GetRoleMenus(arg.Id);
        }
        /// <summary>
        /// 更新指定角色下的菜单排序
        /// </summary>
        [HttpPost]
        public ApiResult UpdateMenuOrder(System.Text.Json.JsonElement arg)
        {
            string roleMenuId = arg.GetString("RoleMenuId");
            int orderNo = arg.GetInt32("OrderNo");
            return BLLObj.UpdateRoleMenuOrder(roleMenuId, orderNo);
        }
        /// <summary>
        /// 更新指定角色下的是否展开
        /// </summary>
        [HttpPost]
        public ApiResult UpdateIsExpand(System.Text.Json.JsonElement arg)
        {
            var roleMenuId = arg.GetString("RoleMenuId");
            var isExpand = arg.GetBoolean("IsExpand");

            return BLLObj.UpdateIsExpand(roleMenuId, isExpand);
        }
    }
}